use cargo::ops;
use cargo::util::{CliResult, CliError, Human, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
use cargo::ops::CompileOptions;
use cargo::ops;
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, CliError, Config};
#[derive(RustcDecodable)]
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let opts = CompileOptions {
config: config,
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let opts = ops::CleanOptions {
config: config,
spec: &options.flag_package,
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let mut doc_opts = ops::DocOptions {
open_result: options.flag_open,
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(RustcDecodable)]
struct Options {
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(ops::fetch(&root, config).map_err(|e| {
CliError::from_boxed(e, 101)
}));
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(RustcDecodable)]
struct Options {
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
ops::generate_lockfile(&root, config)
.map(|_| None).map_err(|err| CliError::from_boxed(err, 101))
use cargo::util::{CliResult, CliError, human, ChainError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct LocateProjectFlags {
}
pub fn execute(flags: LocateProjectFlags,
- _: &Config) -> CliResult<Option<ProjectLocation>> {
- let root = try!(find_root_manifest_for_cwd(flags.flag_manifest_path));
+ config: &Config) -> CliResult<Option<ProjectLocation>> {
+ let root = try!(find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd()));
let string = try!(root.to_str()
.chain_error(|| human("Your project path contains \
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(RustcDecodable)]
struct Options {
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
ops::package(&root, config,
!options.flag_no_verify,
options.flag_list,
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
config: &Config) -> CliResult<Option<()>> {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone()));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd()));
let spec = options.arg_spec.as_ref().map(|s| &s[..]);
let spec = try!(ops::pkgid(&root, spec, config).map_err(|err| {
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(RustcDecodable)]
struct Options {
..
} = options;
- let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
+ let root = try!(find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd()));
ops::publish(&root, config, token, host, !no_verify).map(|_| None).map_err(|err| {
CliError::from_boxed(err, 101)
})
use cargo::core::{Package, Source};
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::sources::{PathSource};
#[derive(RustcDecodable)]
env::args().collect::<Vec<_>>());
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let mut source = try!(PathSource::for_path(root.parent().unwrap(), config).map_err(|e| {
CliError::new(e.description(), 1)
use cargo::ops;
use cargo::util::{CliResult, CliError, Config, Human};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let (mut examples, mut bins) = (Vec::new(), Vec::new());
if let Some(s) = options.flag_bin {
use cargo::ops::CompileOptions;
use cargo::ops;
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, CliError, Config};
#[derive(RustcDecodable)]
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let opts = CompileOptions {
config: config,
use cargo::ops;
use cargo::util::{CliResult, CliError, Human, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(RustcDecodable)]
struct Options {
";
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(RustcDecodable)]
struct Options {
debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
- let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+ let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
let update_opts = ops::UpdateOptions {
aggressive: options.flag_aggressive,
use std::io::prelude::*;
use std::process;
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config};
use rustc_serialize::json;
use toml;
let mut contents = String::new();
let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into());
- let filename = match find_root_manifest_for_cwd(Some(filename)) {
+ let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) {
Ok(manifest_path) => manifest_path,
Err(e) => fail("invalid", &e.to_string()),
};
{
let mut config = None;
let result = (|| {
- config = Some(try!(Config::new(shell(Verbose, Auto))));
+ let cwd = try!(env::current_dir().chain_error(|| {
+ human("couldn't get the current directory of the process")
+ }));
+ config = Some(try!(Config::new(shell(Verbose, Auto), cwd)));
let args: Vec<_> = try!(env::args_os().map(|s| {
s.into_string().map_err(|s| {
human(format!("invalid unicode in argument: {:?}", s))
name
}
-fn existing_vcs_repo(path: &Path) -> bool {
- GitRepo::discover(path).is_ok() || HgRepo::discover(path).is_ok()
+fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
+ GitRepo::discover(path, cwd).is_ok() || HgRepo::discover(path, cwd).is_ok()
}
fn mk(config: &Config, path: &Path, name: &str,
opts: &NewOptions) -> CargoResult<()> {
let cfg = try!(global_config(config));
let mut ignore = "target\n".to_string();
- let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap());
+ let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap(), config.cwd());
if !opts.bin {
ignore.push_str("Cargo.lock\n");
}
match vcs {
VersionControl::Git => {
- try!(GitRepo::init(path));
+ try!(GitRepo::init(path, config.cwd()));
try!(paths::write(&path.join(".gitignore"), ignore.as_bytes()));
},
VersionControl::Hg => {
- try!(HgRepo::init(path));
+ try!(HgRepo::init(path, config.cwd()));
try!(paths::write(&path.join(".hgignore"), ignore.as_bytes()));
},
VersionControl::NoVcs => {
/// specified as well as the exe suffix
fn filename_parts(target: Option<&str>, cfg: &Config)
-> CargoResult<(Option<(String, String)>, String)> {
- let mut process = try!(util::process(cfg.rustc()));
+ let mut process = try!(util::process(cfg.rustc(), cfg.cwd()));
process.arg("-")
.arg("--crate-name").arg("_")
.arg("--crate-type").arg("dylib")
-> CargoResult<CommandPrototype> {
Ok(CommandPrototype {
builder: try!(match ty {
- CommandType::Rustc => process(config.rustc()),
- CommandType::Rustdoc => process(config.rustdoc()),
+ CommandType::Rustc => process(config.rustc(), config.cwd()),
+ CommandType::Rustdoc => process(config.rustdoc(), config.cwd()),
CommandType::Target(ref s) |
- CommandType::Host(ref s) => process(s),
+ CommandType::Host(ref s) => process(s, config.cwd()),
}),
ty: ty,
})
use util::paths;
use util::{CargoResult, human, ChainError, ToUrl};
use util::config::{Config, ConfigValue, Location};
-use util::important_paths::find_root_manifest_for_cwd;
+use util::important_paths::find_root_manifest_for_wd;
pub struct RegistryConfig {
pub index: Option<String>,
let name = match opts.krate {
Some(ref name) => name.clone(),
None => {
- let manifest_path = try!(find_root_manifest_for_cwd(None));
+ let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd()));
let pkg = try!(Package::for_path(&manifest_path, config));
pkg.name().to_string()
}
let name = match krate {
Some(name) => name,
None => {
- let manifest_path = try!(find_root_manifest_for_cwd(None));
+ let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd()));
let pkg = try!(Package::for_path(&manifest_path, config));
pkg.name().to_string()
}
}
impl Config {
- pub fn new(shell: MultiShell) -> CargoResult<Config> {
- let cwd = try!(env::current_dir().chain_error(|| {
- human("couldn't get the current directory of the process")
- }));
-
+ pub fn new(shell: MultiShell, cwd: PathBuf) -> CargoResult<Config> {
let mut cfg = Config {
home_path: try!(homedir(cwd.as_path()).chain_error(|| {
human("Cargo couldn't find your home directory. \
}
fn scrape_rustc_version(&mut self) -> CargoResult<()> {
- self.rustc_info = try!(Rustc::new(&self.rustc));
+ self.rustc_info = try!(Rustc::new(&self.rustc, self.cwd()));
Ok(())
}
-use std::env;
use std::fs;
use std::path::{Path, PathBuf};
-use util::{CargoResult, human, ChainError};
+use util::{CargoResult, human};
/// Iteratively search for `file` in `pwd` and its parents, returning
/// the path of the directory.
}
/// Find the root Cargo.toml
-pub fn find_root_manifest_for_cwd(manifest_path: Option<String>)
+pub fn find_root_manifest_for_wd(manifest_path: Option<String>, cwd: &Path)
-> CargoResult<PathBuf> {
- let cwd = try!(env::current_dir().chain_error(|| {
- human("Couldn't determine the current working directory")
- }));
match manifest_path {
Some(path) => {
let absolute_path = cwd.join(&path);
pub fn get_args(&self) -> &[OsString] {
&self.args
}
- pub fn get_cwd(&self) -> &Path { Path::new(&self.cwd) }
+ pub fn get_cwd(&self) -> &Path {
+ Path::new(&self.cwd)
+ }
pub fn get_env(&self, var: &str) -> Option<OsString> {
self.env.get(var).cloned().or_else(|| Some(env::var_os(var)))
pub fn build_command(&self) -> Command {
let mut command = Command::new(&self.program);
- command.current_dir(&self.cwd);
+ command.current_dir(&self.get_cwd());
for arg in self.args.iter() {
command.arg(arg);
}
}
}
-pub fn process<T: AsRef<OsStr>>(cmd: T) -> CargoResult<ProcessBuilder> {
+pub fn process<T: AsRef<OsStr>, U: AsRef<OsStr>>(cmd: T, cwd: U) -> CargoResult<ProcessBuilder> {
Ok(ProcessBuilder {
program: cmd.as_ref().to_os_string(),
args: Vec::new(),
- cwd: try!(env::current_dir()).as_os_str().to_os_string(),
+ cwd: cwd.as_ref().to_os_string(),
env: HashMap::new(),
})
}
///
/// If successful this function returns a description of the compiler along
/// with a list of its capabilities.
- pub fn new<P: AsRef<Path>>(path: P) -> CargoResult<Rustc> {
- let mut cmd = try!(util::process(path.as_ref()));
+ pub fn new<P: AsRef<Path>>(path: P, cwd: &Path) -> CargoResult<Rustc> {
+ let mut cmd = try!(util::process(path.as_ref(), cwd));
cmd.arg("-vV");
let mut ret = Rustc::blank();
pub struct GitRepo;
impl GitRepo {
- pub fn init(path: &Path) -> CargoResult<GitRepo> {
+ pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
try!(git2::Repository::init(path));
return Ok(GitRepo)
}
- pub fn discover(path: &Path) -> Result<git2::Repository,git2::Error> {
+ pub fn discover(path: &Path, _: &Path) -> Result<git2::Repository,git2::Error> {
git2::Repository::discover(path)
}
}
impl HgRepo {
- pub fn init(path: &Path) -> CargoResult<HgRepo> {
- try!(try!(process("hg")).arg("init").arg(path).exec());
+ pub fn init(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
+ try!(try!(process("hg", cwd)).arg("init").arg(path).exec());
return Ok(HgRepo)
}
- pub fn discover(path: &Path) -> CargoResult<HgRepo> {
- try!(try!(process("hg")).arg("root").cwd(path).exec_with_output());
+ pub fn discover(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
+ try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output());
return Ok(HgRepo)
}
}